package cn.tedu.property.management.controller;

import cn.tedu.property.management.pojo.dto.MaintenanceBusinessAddNewDTO;
import cn.tedu.property.management.pojo.dto.OrderUpdateDTO;
import cn.tedu.property.management.pojo.vo.OrderListItemVO;
import cn.tedu.property.management.pojo.vo.OrderStandardVO;
import cn.tedu.property.management.service.IMaintenanceService;
import cn.tedu.property.management.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理维修业务的控制层
 */
@Slf4j
@RestController
@RequestMapping("/order")
@Api(tags = "维修订单管理模块")
public class MaintenanceController {

    @Autowired
    private IMaintenanceService maintenanceService;


    @PostMapping("/add-new")
    @ApiOperation("新增维修订单")
    @ApiOperationSupport(order = 100)
    public JsonResult insert(MaintenanceBusinessAddNewDTO businessAddNewDTO){
        log.info("开始处理添加维修订单的请求,");
        maintenanceService.addNew(businessAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("根据id删除维修订单")
    @ApiImplicitParam(value = "id",name = "id",example = "1")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteById(@PathVariable Long id){
        log.info("开始处理删除维修订单的请求,");
        maintenanceService.deleteByOrderId(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改维修订单")
    @ApiOperationSupport(order = 300)
    public JsonResult update(Long id, OrderUpdateDTO orderUpdateDTO){
        log.info("开始处理修改维修订单的请求,");
        maintenanceService.updateOrder(id,orderUpdateDTO);
        return JsonResult.ok();
    }

    @PostMapping("/select/detail/byId")
    @ApiOperation("根据id查询订单详情")
    @ApiOperationSupport(order = 400)
    public JsonResult<OrderStandardVO> update(Long id){
        log.info("开始处理根据id查询订单详情的请求,");
        OrderStandardVO details = maintenanceService.getOrderDetailsById(id);
        return JsonResult.ok(details);
    }

    @PostMapping("/select/detail/byName")
    @ApiOperation("根据业主姓名查询订单详情")
    @ApiOperationSupport(order = 500)
    public JsonResult<OrderStandardVO> updateByName(String name){
        log.info("开始处理根据业主姓名查询订单详情的请求,");
        OrderStandardVO details = maintenanceService.getOrderDetailsByOwnerName(name);
        return JsonResult.ok(details);
    }


    @PostMapping("/select/detail/all")
    @ApiOperation("查询所有维修订单")
    @ApiOperationSupport(order = 600)
    public JsonResult<List<OrderListItemVO>> getAll(){
        log.info("开始处理查询所有维修订单的请求,");
        List<OrderListItemVO> orders = maintenanceService.getAll();
        return JsonResult.ok(orders);
    }



























}
